import * as types from '../mutations'

import http from '../../http'

const state = {
    vm:'',
    content_list:[]
}

const getters = {
    content_list: state => state.content_list
}

const mutations = {
    [types.SET_VM] : (state,payload) => {
        state.vm = payload
    },
    [types.SET_CONTENT_LIST] : (state, payload) => {
        state.content_list = payload
    },
}

const actions = {
    query_content({state, commit}, payload) {
        http('/api/config/query_content', {}, res => {
            if(res.code === 0) {
                commit('SET_CONTENT_LIST', res.data)
            }
        })
    },
    create_content(context, payload) {
        var vm = context.state.vm
        http('/api/config/create_content', payload, res=> {
            vm.content_visible = false
            vm.$message.success(res.message)
            context.dispatch("query_content")
        })
    },
    del_content(context, payload) {
        var vm = context.state.vm
        http('/api/config/del_content', payload, res => {
            if(res.code === 0){
                vm.$message.success(res.message)
            }else{
                vm.$message.error(res.message)
            }
            context.dispatch('query_content')
        })
    }
}

export default {
    state,
    getters,
    mutations,
    actions

}

